package top.zlhy7.module.work.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zlhy7.base.request.PageQueryVo;
import top.zlhy7.base.response.ResultVO;
import top.zlhy7.module.work.service.IWordOrderService;
import top.zlhy7.module.work.vo.WordOrderVo;
import top.zlhy7.module.work.vo.WorkOrderFenpaiVo;
import top.zlhy7.module.work.vo.WorkOrderStatistics1Vo;
import top.zlhy7.module.work.vo.WorkOrderStatistics2Vo;
import top.zlhy7.module.work.vo.WorkOrderStatistics3Vo;

/**
 * @author renyong
 * @date 2024/9/29 19:38
 * @description 工单表
 */
@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping("order")
public class WordOrderController {
    /**
     * 工单
     */
    private final IWordOrderService wordOrderService;
    /**
     * 分页
     * @param wordOrder 查询条件
     * @param pageQueryVo 分页参数
     * @return
     * @author renyong on 2024/9/29 20:39
     */
    @PostMapping("search")
    public ResultVO page(WordOrderVo wordOrder, PageQueryVo<WordOrderVo> pageQueryVo){
        pageQueryVo.setQuery(wordOrder);
        return ResultVO.ok(wordOrderService.findPage(pageQueryVo));
    }
    /**
     * 详情
     * @param id 主键id
     * @return
     * @author renyong on 2024/9/29 22:40
     */
    @GetMapping("{id:\\d+}")
    public ResultVO detail(@PathVariable Long id){
        return ResultVO.ok(wordOrderService.getById(id));
    }
    /**
     * 新增
     * @param wordOrderVo 新增参数
     * @return
     * @author renyong on 2024/9/29 22:02
     */
    @PostMapping("save")
    public ResultVO insert(@RequestBody @Validated WordOrderVo wordOrderVo){
        wordOrderService.insert(wordOrderVo);
        return ResultVO.ok();
    }
    /**
     * 修改
     * @param wordOrderVo 修改参数
     * @return
     * @author renyong on 2024/9/29 22:02
     */
    @PostMapping("update")
    public ResultVO update(@RequestBody @Validated WordOrderVo wordOrderVo){
        wordOrderService.update(wordOrderVo);
        return ResultVO.ok();
    }
    /**
     * 删除
     * @param id 主键id
     * @return
     * @author renyong on 2024/9/29 22:02
     */
    @PostMapping("delete")
    public ResultVO delete(Long id){
        wordOrderService.delete(id);
        return ResultVO.ok();
    }
    /**
     * 分派
     * @param workOrderFenpaiVo 分派vo
     * @return
     * @author renyong on 2024/9/29 22:30
     */
    @PostMapping("fenpai")
    public ResultVO fenpai(@RequestBody @Validated WorkOrderFenpaiVo workOrderFenpaiVo){
        wordOrderService.fenpai(workOrderFenpaiVo);
        return ResultVO.ok();
    }
    /**
     * 工单统计1-查询7月每天的工单总量、超期率，超期率=超期工单总量/工单总量
     * @param queryVo 查询条件
     * @return
     */
    @GetMapping("statistics1")
    public ResultVO statistics1(WorkOrderStatistics1Vo queryVo){
        return ResultVO.ok(wordOrderService.statistics1(queryVo));
    }
    /**
     * 工单统计2：查询7月每个部门的工单总量、超期率。
     * @param queryVo 查询条件
     * @return
     */
    @GetMapping("statistics2")
    public ResultVO statistics2(WorkOrderStatistics2Vo queryVo){
        return ResultVO.ok(wordOrderService.statistics2(queryVo));
    }
    /**
     * 工单统计3：查询7月每个工单类型的工单总量、超期率。
     * @param queryVo 查询条件
     * @return
     */
    @GetMapping("statistics3")
    public ResultVO statistics3(WorkOrderStatistics3Vo queryVo){
        return ResultVO.ok(wordOrderService.statistics3(queryVo));
    }
}
